import { Injectable } from "@angular/core";
import { HttpClient, HttpParams } from "@angular/common/http";
import { Observable } from "rxjs";
@Injectable({
  providedIn: 'root'
})
export class GoodsPublicnoteService {
  public GET_URL = "/goodspublicnote/list/page";
  public DELETE_URL = "/goodspublicnote/remove/";
  public ADD_URL = "/goodspublicnote/add";
  public UPDATE_URL = "/goodspublicnote/update";
  public GETITEM_URL = "/goodspublicnote/get/";

  /**
   * 文件上传地址
   */
  public FILE_URL = "/common/upload/file";
  constructor(public httpClient: HttpClient) { }

  // 查询list
  getTableList(params: any) {
    return this.httpClient.get(this.GET_URL, { params }).toPromise();
  }

  // 删除
  deleteItemData(id: any) {
    const delUrl = `${ this.DELETE_URL }${ id }`;
    return this.httpClient.get(delUrl).toPromise();
  }

  // 新增
  addItemData(params: any) {
    return this.httpClient.post(this.ADD_URL, new HttpParams({ fromObject: params })).toPromise();
  }

  // 编辑
  updateItemData(params: any) {
    return this.httpClient.get(this.UPDATE_URL, { params: params }).toPromise();
  }

  /**
   * 上传文件
   * @param fileToUpload 
   * @returns 
   */
  uploadImgData(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "goods");
    return this.httpClient.post(this.FILE_URL, formData).toPromise();
  }
}
